package com.blb.day20231226redis.config;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    /**
     * 返回布隆过滤器
     * @return
     */
    @Bean
    public RBloomFilter<String> bloomFilter(){
        Config config = new Config();
        //设置IO模式
        config.setTransportMode(TransportMode.NIO);
//        //设置单机模式
//        SingleServerConfig singleServerConfig = config.useSingleServer();
//        //配置服务器地址 ，可以用"rediss://"来启用SSL连接
//        singleServerConfig.setAddress("redis://127.0.0.1:6379");
        //配置集群
        ClusterServersConfig clusterServersConfig = config.useClusterServers();
        clusterServersConfig.addNodeAddress(
                "redis://192.168.223.196:7001","redis://192.168.223.196:7002","redis://192.168.223.196:7003",
                "redis://192.168.223.196:7004", "redis://192.168.223.196:7005","redis://192.168.223.196:7006");
        RedissonClient redisson = Redisson.create(config);
        //创建布隆过滤器
        RBloomFilter<String> bloomFilter = redisson.getBloomFilter("score-filter");
        //初始化 参数1 向量长度 参数2 错误率
        bloomFilter.tryInit(10000000L,0.03);
        return bloomFilter;
    }
}
